package com.mlnx.netty.base.handler;

import com.mlnx.common.utils.MyLog;
import com.mlnx.data.entity.BpInfo;
import com.mlnx.device.entity.Device;
import com.mlnx.netty.base.message.SynBpMessage;
import io.netty.channel.ChannelHandlerContext;



/**
 * Created by amanda.shan on 2018/2/12.
 */
public class PushSynBpHandle extends BaseSimpleChannelInboundHandler<SynBpMessage> {
    private MyLog log = MyLog.getLog(this.getClass());
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, SynBpMessage msg) throws Exception {
        String deviceId = msg.getDeviceId();
        Device device= deviceNettyService.getDevice(deviceId);

        BpInfo bpInfo = new BpInfo();
        bpInfo.setDeviceId(deviceId);
        bpInfo.setPatientId(device.getPatientId());
        bpInfo.setPacketTime(msg.getPacketTime());
        bpInfo.setHeart(msg.getHeart());
        bpInfo.setSbp(msg.getSbp());
        bpInfo.setDbp(msg.getDbp());
        bpInfo.setPosition(msg.getPosition());
        bpInfo.setMethod(msg.getMethod());

        deviceBroadcastService.savaSynXmbp(bpInfo);
        log.info("{}设备上传同步血压到病人ID为：{}",deviceId,device.getPatientId());

    }
}
